<?php
/**
 *      [迷你云] (C)2009-2012 南京恒为网络科技.
 *   软件仅供研究与学习使用，如需商用，请访问www.miniyun.cn获得授权
 * 
 */
?>
<?php




class OAuthSignatureMethod_RSA_SHA1 extends OAuthSignatureMethod
{
	public function name() 
	{
		return 'RSA-SHA1';
	}
	

	
	protected function fetch_public_cert ( $request )
	{
														throw OAuthException2("OAuthSignatureMethod_RSA_SHA1::fetch_public_cert not implemented");
	}
	
	
	
	protected function fetch_private_cert ( $request )
	{
										throw OAuthException2("OAuthSignatureMethod_RSA_SHA1::fetch_private_cert not implemented");
	}


	
	public function signature ( $request, $base_string, $consumer_secret, $token_secret )
	{
				$cert = $this->fetch_private_cert($request);
		
				$privatekeyid = openssl_get_privatekey($cert);
		
				$sig = false;
		$ok  = openssl_sign($base_string, $sig, $privatekeyid);   
		
				openssl_free_key($privatekeyid);
		  
		return $request->urlencode(base64_encode($sig));
	}
	

	
	public function verify ( $request, $base_string, $consumer_secret, $token_secret, $signature )
	{
		$decoded_sig = base64_decode($request->urldecode($signature));
		  
				$cert = $this->fetch_public_cert($request);
		
				$publickeyid = openssl_get_publickey($cert);
		
				$ok = openssl_verify($base_string, $decoded_sig, $publickeyid);   
		
				openssl_free_key($publickeyid);
		return $ok == 1;
	}

}



?>